﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.Auth.Service
{
    public static class StringExtensions
    {
        public delegate bool TryParse<T>(string input, out T value);

        public static T ParseOrDefault<T>(this string input, TryParse<T> tryParse)
        {
            return input.ParseOrDefault(tryParse, default(T));
        }

        public static T ParseOrDefault<T>(this string input, TryParse<T> tryParse, T defaultValue)
        {
            T value;
            return tryParse.Invoke(input, out value) ? value : defaultValue;
        }
    }
}
